package com.mav01.mrpbackend.mapper;

import com.mav01.mrpbackend.pojo.Debt;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DebtMapper {

    // 根据变量名查询行数据
    @Select("SELECT * FROM debt WHERE variable_name = #{variableName}")
    Debt selectByVariable(String variableName);

    // 查询全部数据
    @Select("SELECT * FROM debt WHERE variable_name IS NOT NULL ORDER BY id")
    List<Debt> selectAll();

    // 根据变量名修改一条数据
    @Update("UPDATE debt SET id = #{id}, asset_description = #{assetDescription}, asset_direction = #{assetDirection}, " +
            "summary_sequence = #{summarySequence} WHERE variable_name = #{variableName}")
    int update(Debt debt);

    // 插入一条数据
    @Insert("INSERT INTO debt (id, asset_description, asset_direction, summary_sequence, variable_name) " +
            "VALUES (#{id},#{assetDescription}, #{assetDirection}, #{summarySequence}, #{variableName})")
    int insert(Debt debt);

    // 根据变量名删除一条数据
    @Delete("DELETE FROM debt WHERE variable_name = #{variableName}")
    int deleteByVariable(String variableName);

    // 根据汇总序号查询所有相关变量
    @Select("SELECT * FROM debt WHERE summary_sequence = #{id} AND variable_name IS NOT NULL")
    List<Debt> selectBySummarySequence(Debt debt);

}